package com.gitee.wsl.text.dictomaton.levenshtein

internal class ParametricTransitions1 : ParametricTransitions {
    
    override fun transition(parametricState: Int, offset: Int, characteristicVector: Int, len: Int): Int {
        var parToState = -1
        var parToOffset = 0

        if (offset == len) {
            if (parametricState < 2) {
                val pos = characteristicVector * 2 + parametricState
                parToState = d_toStates[0][pos]
                parToOffset = d_increments[0][pos]
            }
        } else if (offset == len - 1) {
            if (parametricState < 3) {
                val pos = characteristicVector * 3 + parametricState
                parToState = d_toStates[1][pos]
                parToOffset = d_increments[1][pos]
            }
        } else if (offset == len - 2) {
            if (parametricState < 5) {
                val pos = characteristicVector * 5 + parametricState
                parToState = d_toStates[2][pos]
                parToOffset = d_increments[2][pos]
            }
        } else if (offset <= len - 3) {
            if (parametricState < 5) {
                val pos = characteristicVector * 5 + parametricState
                parToState = d_toStates[3][pos]
                parToOffset = d_increments[3][pos]
            }
        }

        if (parToState == -1) return -1

        return ((offset + parToOffset) * d_nStates) + parToState
    }

    
    override fun nParametricStates(): Int {
        return d_nStates
    }

    
    override fun maxOffsetErrors(parametricState: Int): Int {
        return d_maxOffsetErrors[parametricState]
    }

    
    override fun nEditOperations(): Int {
        return 1
    }

    private val d_toStates: Array<IntArray> = arrayOf<IntArray>(
        intArrayOf(1, -1),
        intArrayOf(2, -1, -1, 0, 1, 1),
        intArrayOf(2, -1, -1, -1, -1, 4, -1, 1, -1, 1, 0, 1, 1, 1, 1, 0, 1, 2, 1, 2),
        intArrayOf(
            2,
            -1,
            -1,
            -1,
            -1,
            2,
            -1,
            -1,
            1,
            1,
            4,
            -1,
            1,
            -1,
            1,
            4,
            -1,
            1,
            1,
            2,
            0,
            1,
            1,
            1,
            1,
            0,
            1,
            1,
            3,
            3,
            0,
            1,
            2,
            1,
            2,
            0,
            1,
            2,
            3,
            4
        )
    )
    private val d_increments: Array<IntArray> = arrayOf<IntArray>(
        intArrayOf(0, 0),
        intArrayOf(0, 0, 0, 1, 1, 1),
        intArrayOf(0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1),
        intArrayOf(
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            3,
            3,
            0,
            0,
            2,
            0,
            2,
            0,
            0,
            2,
            3,
            2,
            1,
            1,
            1,
            1,
            1,
            1,
            1,
            1,
            1,
            1,
            1,
            1,
            1,
            1,
            1,
            1,
            1,
            1,
            1,
            1
        )
    )
    private val d_maxOffsetErrors: IntArray = intArrayOf(1, 0, 1, 2, 2)
    private val d_nStates = 5
}
